.shp - geographic coordinates.dbf - data associated with the geographic features.prj - projection of the coordinates in the shapefileUses JavaScript Object Notation (JSON) file format
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}Plain text files
sf
| type | description |
|---|---|
POINT |
zero-dimensional geometry containing a single point |
LINESTRING |
sequence of points connected by straight, non-self intersecting line pieces; one-dimensional geometry |
POLYGON |
geometry with a positive area (two-dimensional); sequence of points form a closed, non-self intersecting ring; the first ring denotes the exterior ring, zero or more subsequent rings denote holes in this exterior ring |
MULTIPOINT |
set of points; a MULTIPOINT is simple if no two Points in the MULTIPOINT are equal |
MULTILINESTRING |
set of linestrings |
MULTIPOLYGON |
set of polygons |
GEOMETRYCOLLECTION |
set of geometries of any type except GEOMETRYCOLLECTION |
sfchi_shape <- st_read("../data/Boundaries - Community Areas (current)/geo_export_328cdcbf-33ba-4997-8ce8-90953c6fec19.shp")## Reading layer `geo_export_328cdcbf-33ba-4997-8ce8-90953c6fec19' from data source `/Users/soltoffbc/Projects/Computing for Social Sciences/uc-cfss.github.io/data/Boundaries - Community Areas (current)/geo_export_328cdcbf-33ba-4997-8ce8-90953c6fec19.shp' using driver `ESRI Shapefile'
## Simple feature collection with 77 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -87.9 ymin: 41.6 xmax: -87.5 ymax: 42
## epsg (SRID): 4326
## proj4string: +proj=longlat +ellps=WGS84 +no_defs
chi_shape## Simple feature collection with 77 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -87.9 ymin: 41.6 xmax: -87.5 ymax: 42
## epsg (SRID): 4326
## proj4string: +proj=longlat +ellps=WGS84 +no_defs
## First 10 features:
## perimeter community shape_len shape_area area comarea area_numbe
## 1 0 DOUGLAS 31027 46004621 0 0 35
## 2 0 OAKLAND 19566 16913961 0 0 36
## 3 0 FULLER PARK 25339 19916705 0 0 37
## 4 0 GRAND BOULEVARD 28197 48492503 0 0 38
## 5 0 KENWOOD 23325 29071742 0 0 39
## 6 0 LINCOLN SQUARE 36625 71352328 0 0 4
## 7 0 WASHINGTON PARK 28175 42373881 0 0 40
## 8 0 HYDE PARK 29747 45105380 0 0 41
## 9 0 WOODLAWN 46937 57815180 0 0 42
## 10 0 ROGERS PARK 34052 51259902 0 0 1
## area_num_1 comarea_id geometry
## 1 35 0 MULTIPOLYGON (((-87.6 41.8,...
## 2 36 0 MULTIPOLYGON (((-87.6 41.8,...
## 3 37 0 MULTIPOLYGON (((-87.6 41.8,...
## 4 38 0 MULTIPOLYGON (((-87.6 41.8,...
## 5 39 0 MULTIPOLYGON (((-87.6 41.8,...
## 6 4 0 MULTIPOLYGON (((-87.7 42, -...
## 7 40 0 MULTIPOLYGON (((-87.6 41.8,...
## 8 41 0 MULTIPOLYGON (((-87.6 41.8,...
## 9 42 0 MULTIPOLYGON (((-87.6 41.8,...
## 10 1 0 MULTIPOLYGON (((-87.7 42, -...
chi_json <- st_read("../data/Boundaries - Community Areas (current).geojson")## Reading layer `OGRGeoJSON' from data source `/Users/soltoffbc/Projects/Computing for Social Sciences/uc-cfss.github.io/data/Boundaries - Community Areas (current).geojson' using driver `GeoJSON'
## Simple feature collection with 77 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -87.9 ymin: 41.6 xmax: -87.5 ymax: 42
## epsg (SRID): 4326
## proj4string: +proj=longlat +datum=WGS84 +no_defs
chi_json## Simple feature collection with 77 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -87.9 ymin: 41.6 xmax: -87.5 ymax: 42
## epsg (SRID): 4326
## proj4string: +proj=longlat +datum=WGS84 +no_defs
## First 10 features:
## community area shape_area perimeter area_num_1 area_numbe
## 1 DOUGLAS 0 46004621.1581 0 35 35
## 2 OAKLAND 0 16913961.0408 0 36 36
## 3 FULLER PARK 0 19916704.8692 0 37 37
## 4 GRAND BOULEVARD 0 48492503.1554 0 38 38
## 5 KENWOOD 0 29071741.9283 0 39 39
## 6 LINCOLN SQUARE 0 71352328.2399 0 4 4
## 7 WASHINGTON PARK 0 42373881.4842 0 40 40
## 8 HYDE PARK 0 45105380.1732 0 41 41
## 9 WOODLAWN 0 57815179.512 0 42 42
## 10 ROGERS PARK 0 51259902.4506 0 1 1
## comarea_id comarea shape_len geometry
## 1 0 0 31027.0545098 MULTIPOLYGON (((-87.6 41.8,...
## 2 0 0 19565.5061533 MULTIPOLYGON (((-87.6 41.8,...
## 3 0 0 25339.0897503 MULTIPOLYGON (((-87.6 41.8,...
## 4 0 0 28196.8371573 MULTIPOLYGON (((-87.6 41.8,...
## 5 0 0 23325.1679062 MULTIPOLYGON (((-87.6 41.8,...
## 6 0 0 36624.6030848 MULTIPOLYGON (((-87.7 42, -...
## 7 0 0 28175.3160866 MULTIPOLYGON (((-87.6 41.8,...
## 8 0 0 29746.7082016 MULTIPOLYGON (((-87.6 41.8,...
## 9 0 0 46936.9592443 MULTIPOLYGON (((-87.6 41.8,...
## 10 0 0 34052.3975757 MULTIPOLYGON (((-87.7 42, -...
usa <- st_read("../data/census_bureau/cb_2013_us_state_20m/cb_2013_us_state_20m.shp")## Reading layer `cb_2013_us_state_20m' from data source `/Users/soltoffbc/Projects/Computing for Social Sciences/uc-cfss.github.io/data/census_bureau/cb_2013_us_state_20m/cb_2013_us_state_20m.shp' using driver `ESRI Shapefile'
## Simple feature collection with 52 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -179 ymin: 17.9 xmax: 180 ymax: 71.4
## epsg (SRID): 4269
## proj4string: +proj=longlat +datum=NAD83 +no_defs
ggplot(data = usa) +
geom_sf()(usa_48 <- usa %>%
filter(!(NAME %in% c("Alaska", "District of Columbia", "Hawaii", "Puerto Rico"))))## Simple feature collection with 48 features and 9 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -125 ymin: 24.5 xmax: -66.9 ymax: 49.4
## epsg (SRID): 4269
## proj4string: +proj=longlat +datum=NAD83 +no_defs
## First 10 features:
## STATEFP STATENS AFFGEOID GEOID STUSPS NAME LSAD ALAND
## 1 01 01779775 0400000US01 01 AL Alabama 00 1.31e+11
## 2 05 00068085 0400000US05 05 AR Arkansas 00 1.35e+11
## 3 06 01779778 0400000US06 06 CA California 00 4.03e+11
## 4 09 01779780 0400000US09 09 CT Connecticut 00 1.25e+10
## 5 12 00294478 0400000US12 12 FL Florida 00 1.39e+11
## 6 13 01705317 0400000US13 13 GA Georgia 00 1.49e+11
## 7 16 01779783 0400000US16 16 ID Idaho 00 2.14e+11
## 8 17 01779784 0400000US17 17 IL Illinois 00 1.44e+11
## 9 18 00448508 0400000US18 18 IN Indiana 00 9.28e+10
## 10 20 00481813 0400000US20 20 KS Kansas 00 2.12e+11
## AWATER geometry
## 1 4.59e+09 MULTIPOLYGON (((-88.3 30.2,...
## 2 2.96e+09 MULTIPOLYGON (((-94.6 36.5,...
## 3 2.05e+10 MULTIPOLYGON (((-119 33.5, ...
## 4 1.82e+09 MULTIPOLYGON (((-73.7 41.1,...
## 5 3.14e+10 MULTIPOLYGON (((-80.7 24.9,...
## 6 4.95e+09 MULTIPOLYGON (((-85.6 35, -...
## 7 2.40e+09 MULTIPOLYGON (((-117 44.4, ...
## 8 6.20e+09 MULTIPOLYGON (((-91.5 40.2,...
## 9 1.54e+09 MULTIPOLYGON (((-88.1 37.9,...
## 10 1.35e+09 MULTIPOLYGON (((-102 40, -1...
ggplot(data = usa_48) +
geom_sf()fiftystaterlibrary(fiftystater)
data("fifty_states")
as_tibble(fifty_states)## # A tibble: 13,694 x 7
## long lat order hole piece id group
## <dbl> <dbl> <int> <lgl> <fct> <chr> <fct>
## 1 -85.1 32.0 1 FALSE 1 alabama Alabama.1
## 2 -85.1 31.9 2 FALSE 1 alabama Alabama.1
## 3 -85.1 31.9 3 FALSE 1 alabama Alabama.1
## 4 -85.1 31.8 4 FALSE 1 alabama Alabama.1
## 5 -85.1 31.8 5 FALSE 1 alabama Alabama.1
## 6 -85.1 31.7 6 FALSE 1 alabama Alabama.1
## 7 -85.1 31.7 7 FALSE 1 alabama Alabama.1
## 8 -85.1 31.7 8 FALSE 1 alabama Alabama.1
## 9 -85.1 31.6 9 FALSE 1 alabama Alabama.1
## 10 -85.0 31.6 10 FALSE 1 alabama Alabama.1
## # ... with 13,684 more rows
fiftystater to sfst_as_sf(fifty_states, coords = c("long", "lat"))## Simple feature collection with 13694 features and 5 fields
## geometry type: POINT
## dimension: XY
## bbox: xmin: -125 ymin: 23.5 xmax: -67 ymax: 49.4
## epsg (SRID): NA
## proj4string: NA
## First 10 features:
## order hole piece id group geometry
## 1 1 FALSE 1 alabama Alabama.1 POINT (-85.1 32)
## 2 2 FALSE 1 alabama Alabama.1 POINT (-85.1 31.9)
## 3 3 FALSE 1 alabama Alabama.1 POINT (-85.1 31.9)
## 4 4 FALSE 1 alabama Alabama.1 POINT (-85.1 31.8)
## 5 5 FALSE 1 alabama Alabama.1 POINT (-85.1 31.8)
## 6 6 FALSE 1 alabama Alabama.1 POINT (-85.1 31.7)
## 7 7 FALSE 1 alabama Alabama.1 POINT (-85.1 31.7)
## 8 8 FALSE 1 alabama Alabama.1 POINT (-85.1 31.7)
## 9 9 FALSE 1 alabama Alabama.1 POINT (-85.1 31.6)
## 10 10 FALSE 1 alabama Alabama.1 POINT (-85 31.6)
st_as_sf(fifty_states, coords = c("long", "lat")) %>%
# convert sets of points to polygons
group_by(id, piece) %>%
summarize(do_union = FALSE) %>%
st_cast("POLYGON")## Simple feature collection with 134 features and 3 fields
## geometry type: POLYGON
## dimension: XY
## bbox: xmin: -125 ymin: 23.5 xmax: -67 ymax: 49.4
## epsg (SRID): NA
## proj4string: NA
## First 10 features:
## id piece do_union geometry
## 1 alabama 1 FALSE POLYGON ((-85.1 32, -85.1 3...
## 2 alaska 1 FALSE POLYGON ((-120 25.8, -120 2...
## 3 alaska 2 FALSE POLYGON ((-118 25.2, -118 2...
## 4 alaska 3 FALSE POLYGON ((-113 25.4, -113 2...
## 5 alaska 4 FALSE POLYGON ((-114 26.1, -114 2...
## 6 alaska 5 FALSE POLYGON ((-121 27.9, -121 2...
## 7 alaska 6 FALSE POLYGON ((-114 26, -114 26,...
## 8 alaska 7 FALSE POLYGON ((-120 26.6, -120 2...
## 9 alaska 8 FALSE POLYGON ((-120 24.2, -120 2...
## 10 alaska 9 FALSE POLYGON ((-114 25.5, -114 2...
# convert fifty_states to an sf data frame
(sf_fifty <- st_as_sf(fifty_states, coords = c("long", "lat")) %>%
# convert sets of points to polygons
group_by(id, piece) %>%
summarize(do_union = FALSE) %>%
st_cast("POLYGON") %>%
# convert polygons to multipolygons for states with discontinuous regions
group_by(id) %>%
summarize())## Simple feature collection with 51 features and 1 field
## geometry type: GEOMETRY
## dimension: XY
## bbox: xmin: -125 ymin: 23.5 xmax: -67 ymax: 49.4
## epsg (SRID): NA
## proj4string: NA
## # A tibble: 51 x 2
## id geometry
## <chr> <GEOMETRY>
## 1 alabama POLYGON ((-85.1 32, -85.1 31.9, -85.1 31.9, -85.1 31.8…
## 2 alaska MULTIPOLYGON (((-123 23.6, -123 23.6, -123 23.7, -123 …
## 3 arizona POLYGON ((-115 33, -115 33, -115 33, -115 33, -115 33,…
## 4 arkansas POLYGON ((-94.5 34.2, -94.5 34.5, -94.4 34.7, -94.4 34…
## 5 california MULTIPOLYGON (((-118 32.8, -118 32.8, -119 32.9, -119 …
## 6 colorado POLYGON ((-102 37.6, -102 37.4, -102 37, -103 37, -103…
## 7 connecticut POLYGON ((-73.5 41.5, -73.5 41.7, -73.5 42, -73 42, -7…
## 8 delaware POLYGON ((-75.7 38.6, -75.7 38.6, -75.7 38.8, -75.8 39…
## 9 district of co… POLYGON ((-77 39, -76.9 38.9, -77 38.8, -77 38.8, -77 …
## 10 florida MULTIPOLYGON (((-80.2 25.4, -80.4 25.2, -80.6 25, -80.…
## # ... with 41 more rows
st_crs(sf_fifty) <- 4326fiftystater to sfggplot(data = sf_fifty) +
geom_sf()library(nycflights13)
airports## # A tibble: 1,458 x 8
## faa name lat lon alt tz dst tzone
## <chr> <chr> <dbl> <dbl> <int> <dbl> <chr> <chr>
## 1 04G Lansdowne Airport 41.1 -80.6 1044 -5 A America/New_…
## 2 06A Moton Field Municip… 32.5 -85.7 264 -6 A America/Chic…
## 3 06C Schaumburg Regional 42.0 -88.1 801 -6 A America/Chic…
## 4 06N Randall Airport 41.4 -74.4 523 -5 A America/New_…
## 5 09J Jekyll Island Airpo… 31.1 -81.4 11 -5 A America/New_…
## 6 0A9 Elizabethton Munici… 36.4 -82.2 1593 -5 A America/New_…
## 7 0G6 Williams County Air… 41.5 -84.5 730 -5 A America/New_…
## 8 0G7 Finger Lakes Region… 42.9 -76.8 492 -5 A America/New_…
## 9 0P2 Shoestring Aviation… 39.8 -76.6 1000 -5 U America/New_…
## 10 0S9 Jefferson County In… 48.1 -123. 108 -8 A America/Los_…
## # ... with 1,448 more rows
ggplot(airports, aes(lon, lat)) +
geom_point()ggplot(data = usa_48) +
geom_sf() +
geom_point(data = airports, aes(x = lon, y = lat), shape = 1)ggplot(data = usa_48) +
geom_sf() +
geom_point(data = airports, aes(x = lon, y = lat), shape = 1) +
coord_sf(xlim = c(-130, -60),
ylim = c(20, 50))airports_sf <- st_as_sf(airports, coords = c("lon", "lat"))
st_crs(airports_sf) <- 4326 # set the coordinate reference system
airports_sf## Simple feature collection with 1458 features and 6 fields
## geometry type: POINT
## dimension: XY
## bbox: xmin: -177 ymin: 19.7 xmax: 174 ymax: 72.3
## epsg (SRID): 4326
## proj4string: +proj=longlat +datum=WGS84 +no_defs
## # A tibble: 1,458 x 7
## faa name alt tz dst tzone geometry
## <chr> <chr> <int> <dbl> <chr> <chr> <POINT [°]>
## 1 04G Lansdowne Airp… 1044 -5 A America/N… (-80.6 41.1)
## 2 06A Moton Field Mu… 264 -6 A America/C… (-85.7 32.5)
## 3 06C Schaumburg Reg… 801 -6 A America/C… (-88.1 42)
## 4 06N Randall Airport 523 -5 A America/N… (-74.4 41.4)
## 5 09J Jekyll Island … 11 -5 A America/N… (-81.4 31.1)
## 6 0A9 Elizabethton M… 1593 -5 A America/N… (-82.2 36.4)
## 7 0G6 Williams Count… 730 -5 A America/N… (-84.5 41.5)
## 8 0G7 Finger Lakes R… 492 -5 A America/N… (-76.8 42.9)
## 9 0P2 Shoestring Avi… 1000 -5 U America/N… (-76.6 39.8)
## 10 0S9 Jefferson Coun… 108 -8 A America/L… (-123 48.1)
## # ... with 1,448 more rows
ggplot() +
geom_sf(data = usa_48) +
geom_sf(data = airports_sf, shape = 1) +
coord_sf(xlim = c(-130, -60),
ylim = c(20, 50))ggplot(data = usa_48) +
geom_sf() +
geom_point(data = airports, aes(x = lon, y = lat, size = alt),
fill = "grey", color = "black", alpha = .2) +
coord_sf(xlim = c(-130, -60),
ylim = c(20, 50)) +
scale_size_area(guide = FALSE)airports_n <- flights %>%
count(dest) %>%
left_join(airports, by = c("dest" = "faa"))
ggplot(data = usa_48) +
geom_sf() +
geom_point(data = airports_n, aes(x = lon, y = lat, size = n),
fill = "grey", color = "black", alpha = .2) +
coord_sf(xlim = c(-130, -60),
ylim = c(20, 50)) +
scale_size_area(guide = FALSE)(fb_state <- read_csv("../data/census_bureau/ACS_13_5YR_B05012_state/ACS_13_5YR_B05012.csv") %>%
mutate(rate = HD01_VD03 / HD01_VD01))## # A tibble: 51 x 10
## GEO.id GEO.id2 `GEO.display-la… HD01_VD01 HD02_VD01 HD01_VD02 HD02_VD02
## <chr> <chr> <chr> <int> <chr> <int> <int>
## 1 04000… 01 Alabama 4799277 <NA> 4631045 2881
## 2 04000… 02 Alaska 720316 <NA> 669941 1262
## 3 04000… 04 Arizona 6479703 <NA> 5609835 7725
## 4 04000… 05 Arkansas 2933369 <NA> 2799972 2568
## 5 04000… 06 California 37659181 <NA> 27483342 30666
## 6 04000… 08 Colorado 5119329 <NA> 4623809 5778
## 7 04000… 09 Connecticut 3583561 <NA> 3096374 5553
## 8 04000… 10 Delaware 908446 <NA> 831683 2039
## 9 04000… 11 District of Col… 619371 <NA> 534142 2017
## 10 04000… 12 Florida 19091156 <NA> 15392410 16848
## # ... with 41 more rows, and 3 more variables: HD01_VD03 <int>,
## # HD02_VD03 <int>, rate <dbl>
(usa_fb <- usa_48 %>%
left_join(fb_state, by = c("STATEFP" = "GEO.id2")))## Simple feature collection with 48 features and 18 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -125 ymin: 24.5 xmax: -66.9 ymax: 49.4
## epsg (SRID): 4269
## proj4string: +proj=longlat +datum=NAD83 +no_defs
## First 10 features:
## STATEFP STATENS AFFGEOID GEOID STUSPS NAME LSAD ALAND
## 1 01 01779775 0400000US01 01 AL Alabama 00 1.31e+11
## 2 05 00068085 0400000US05 05 AR Arkansas 00 1.35e+11
## 3 06 01779778 0400000US06 06 CA California 00 4.03e+11
## 4 09 01779780 0400000US09 09 CT Connecticut 00 1.25e+10
## 5 12 00294478 0400000US12 12 FL Florida 00 1.39e+11
## 6 13 01705317 0400000US13 13 GA Georgia 00 1.49e+11
## 7 16 01779783 0400000US16 16 ID Idaho 00 2.14e+11
## 8 17 01779784 0400000US17 17 IL Illinois 00 1.44e+11
## 9 18 00448508 0400000US18 18 IN Indiana 00 9.28e+10
## 10 20 00481813 0400000US20 20 KS Kansas 00 2.12e+11
## AWATER GEO.id GEO.display-label HD01_VD01 HD02_VD01 HD01_VD02
## 1 4.59e+09 0400000US01 Alabama 4799277 <NA> 4631045
## 2 2.96e+09 0400000US05 Arkansas 2933369 <NA> 2799972
## 3 2.05e+10 0400000US06 California 37659181 <NA> 27483342
## 4 1.82e+09 0400000US09 Connecticut 3583561 <NA> 3096374
## 5 3.14e+10 0400000US12 Florida 19091156 <NA> 15392410
## 6 4.95e+09 0400000US13 Georgia 9810417 <NA> 8859747
## 7 2.40e+09 0400000US16 Idaho 1583364 <NA> 1489560
## 8 6.20e+09 0400000US17 Illinois 12848554 <NA> 11073828
## 9 1.54e+09 0400000US18 Indiana 6514861 <NA> 6206801
## 10 1.35e+09 0400000US20 Kansas 2868107 <NA> 2677007
## HD02_VD02 HD01_VD03 HD02_VD03 rate geometry
## 1 2881 168232 2881 0.0351 MULTIPOLYGON (((-88.3 30.2,...
## 2 2568 133397 2568 0.0455 MULTIPOLYGON (((-94.6 36.5,...
## 3 30666 10175839 30666 0.2702 MULTIPOLYGON (((-119 33.5, ...
## 4 5553 487187 5553 0.1360 MULTIPOLYGON (((-73.7 41.1,...
## 5 16848 3698746 16848 0.1937 MULTIPOLYGON (((-80.7 24.9,...
## 6 7988 950670 7988 0.0969 MULTIPOLYGON (((-85.6 35, -...
## 7 2528 93804 2528 0.0592 MULTIPOLYGON (((-117 44.4, ...
## 8 10091 1774726 10093 0.1381 MULTIPOLYGON (((-91.5 40.2,...
## 9 4499 308060 4500 0.0473 MULTIPOLYGON (((-88.1 37.9,...
## 10 3095 191100 3100 0.0666 MULTIPOLYGON (((-102 40, -1...
ggplot(data = usa_fb) +
geom_sf(aes(fill = rate))cut_interval()usa_fb %>%
mutate(rate_cut = cut_interval(rate, 6)) %>%
ggplot() +
geom_sf(aes(fill = rate_cut))cut_number()usa_fb %>%
mutate(rate_cut = cut_number(rate, 6)) %>%
ggplot() +
geom_sf(aes(fill = rate_cut))proj4stringmap_proj_base <- ggplot(data = usa_48) +
geom_sf()map_proj_base +
coord_sf(crs = "+proj=merc") +
ggtitle("Mercator projection")map_proj_base +
coord_sf(crs = "+proj=cea +lon_0=0 +lat_ts=45") +
ggtitle("Gall-Peters projection")map_proj_base +
coord_sf(crs = "+proj=aea +lat_1=25 +lat_2=50 +lon_0=-100") +
ggtitle("Albers equal-area projection")map_proj_base +
coord_sf(crs = "+proj=laea +lat_0=35 +lon_0=-100") +
ggtitle("Lambert azimuthal projection")